package leecode

import (
	"sort"
	"strings"
)

func smallestSubsequence(s string) string {
	hashMap := make(map[byte]int)
	for index, _ := range s {
		hashMap[s[index]]++
	}
	var resStr string
	for key, _ := range hashMap {
		resStr += string(key)
	}
	sort.Strings(strings.Split(resStr, ""))
	resByte := []byte(resStr)
	for i, j := 0, len(resStr)-1; i < j; i, j = i+1, j-1 {
		resByte[i], resByte[j] = resByte[j], resByte[i]
	}
	return string(resByte)
}
